<?php
class collectionController extends userController{
    
    public function index() {
        //分页参数
        $url=url('message/index',array('page'=>'{page}','type'=>intval($_GET['tpye'])));
        $limit = $this->pageLimit($url, 20);
        //列表信息
        $loop=model('collection')->collection_list($limit,$this->user_id);
        $count=model('collection')->count($this->user_id);
        if(!empty($loop)){
            $i=0;
            foreach ($loop as $key=>$value) {
                $i++;
                $list[$key]=$value;
                $list[$key]['aurl']=api('product','get_aurl',$value);
                $list[$key]['i']=$i;
            }
        }
        $this->list=$list;
        $this->page=$this->pageShow($count);
        $this->show();  
    }

    public function add() {
        $aid=intval($_GET['aid']);
        if(empty($aid)){
            $this->errorpage('通讯发生错误，请稍后重试！');
        }
        
        //重复收藏
        if(model('collection')->info($this->user_id,$aid)){
            $this->alert('您已经收藏过该内容，无法重复收藏！');
        }
        
        $this->info=model('collection')->content($aid);
        if(!$this->info){
            $this->alert('没有发现该内容信息！');
        }

        $this->show(); 
    }

    public function add_data() {
        $data=in($_POST);
        if(empty($data['aid'])){
            $this->errorpage('通讯发生错误，请稍后重试！');
        }
        
        //重复收藏
        if(model('collection')->info($this->user_id,$data['aid'])){
            $this->msg('您已经收藏过该内容，无法重复收藏！',0);
        }

        $info=model('collection')->content($data['aid']);
        if(!$info){
            $this->msg('没有发现该内容信息！',0);
        }
        $data['uid']=$this->user_id;
        model('collection')->add($data);
        $this->msg(url('collection/index'));
    }

    public function del() {
        $data=in($_POST);
        if(empty($data['aid'])){
            $this->msg('通讯发生错误，请稍后重试！');
        }
        model('collection')->del($this->user_id,$data['aid']);
        $this->msg('已删除该收藏！');
    }

}